import { GeneralReturnValue } from "@/types/general";
import {
  getSystemSettingsReturnValue,
  getloadUserListReturnValue,
} from "@/types/setting";
import http from "@/utils/axios";

/**
 * 获取系统设置
 * @returns
 */
export const getSystemSettingsAPI = () =>
  http<getSystemSettingsReturnValue>({
    url: "/admin/getSysSettings",
    method: "POST",
  });

/**
 * 保存系统设置
 * @param data 发送邮箱标题,发送邮箱内容,用户初始化空间配额
 * @returns
 */
export const saveSystemSettingsAPI = (data: {
  registerEmailTitle: string;
  registerEmailContent: string;
  userInitUseSpace: string;
}) =>
  http<GeneralReturnValue>({
    url: "/admin/saveSysSettings",
    method: "POST",
    data,
  });

/**
 * 获取用户列表
 * @param data 页码,分页大小,昵称模糊搜索,状态
 * @returns
 */
export const getloadUserListAPI = (data: {
  pageNo: string;
  pageSize: string;
  nickNameFuzzy: string;
  status: string;
}) =>
  http<getloadUserListReturnValue>({
    url: "/admin/loadUserList",
    method: "POST",
    data,
  });

/**
 * 修改用户状态
 * @param data 用户ID,状态
 * @returns
 */
export const modifyingUserStatusAPI = (data: {
  userId: string;
  status: string;
}) =>
  http<any>({
    url: "/admin/updateUserStatus",
    method: "POST",
    data,
  });

/**
 * 修改用户空间
 * @param data 用户ID,改变的空间 单位MB
 * @returns
 */
export const modifyingUserSpaceAPI = (data: {
  userId: string;
  changeSpace: string;
}) =>
  http<any>({
    url: "/admin/updateUserSpace",
    method: "POST",
    data,
  });

/**
 * 获取所有文件
 * @param data 页码,分页大小,文件名模糊搜索
 * @returns
 */
export const getAllFilesAPI = (data: {
  pageNo: string;
  pageSize: string;
  fileNameFuzzy: string;
}) =>
  http<any>({
    url: "/admin/loadFileList",
    method: "POST",
    data,
  });

/**
 * 获取当前目录信息
 * @param data 路径
 * @returns
 */
export const getCurrentDirectoryInformationAPI = (data: { path: string }) =>
  http<any>({
    url: "/admin/getFolderInfo",
    method: "POST",
    data,
  });

/**
 * 获取文件信息
 * @param data 用户ID,文件ID
 * @returns
 */
export const getFilesInformationAPI = (userId: string, fileId: string) =>
  http<any>({
    url: `/admin/getFile/${userId}/${fileId}`,
    method: "GET",
  });

/**
 * 创建下载链接
 * @param data 用户ID,文件ID
 * @returns
 */
export const createDownloadLinkAPI = (userId: string, fileId: string) =>
  http<any>({
    url: `/admin/createDownloadUrl/${userId}/${fileId}`,
    method: "POST",
  });

/**
 * 下载文件
 * @param data 创建下载链接返回的code
 * @returns
 */
export const downloadFilesAPI = (data: { code: string }) =>
  http<any>({
    url: "/api/download",
    method: "GET",
    data,
  });

/**
 * 删除文件
 * @param data 文件和用户ID用_隔开，多个参数用 逗号隔开
 * @returns
 */
export const deleteFilesAPI = (data: { fileIdAndUserIds: string }) =>
  http<any>({
    url: "/api/delFile",
    method: "POST",
    data,
  });
